<?php

namespace App\Exceptions;

use App\Common\Api\SystemCode;
use App\Common\Api\SystemMessage;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * The list of the inputs that are never flashed to the session on validation exceptions.
     *
     * @var array<int, string>
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     */
    public function register(): void
    {
        $this->reportable(function (Throwable $e) {
            //
        });
    }

    // Api 接口 处理状态为 404
    public function render($request, Throwable $e)
    {
        if ($e instanceof NotFoundHttpException) {
            return response()->json([
                'code' => SystemCode::SYSTEM_API_INVALID,
                'message'=>SystemMessage::SYSTEM_API_INVALID,
                'data'=>[],
            ]);
        }

        return parent::render($request, $e);
    }
}
